home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BMUG Revelations
/
BMUG Revelations.toast
/
Utilities
/
System 7
/
CloakShare
/
CloakShare.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-18
|
3KB
|
158 lines
/*
CloakShare
By Eric Traut & Dan Clifford
June 17, 1993
See accompanying ReadMe file for more info
*/
#include <Types.h>
#include <SetUpA4.h>
#include <OSUtils.h>
#include <Files.h>
#include <Traps.h>
#include <AppleTalk.h>
#define kPBControlTrap 0xA004
#define PushRegs() asm { movem.l a0-a1/a4/d0-d1,-(sp) };
#define PopRegs() asm { movem.l (sp)+, a0-a1/a4/d0-d1 };
typedef pascal OSErr (* PBRoutinePtr)(CntrlParam *someParamBlock);
/* global variables accessed via THINK’s A4 world */
static PBRoutinePtr OriginalPBControl;
static char fileShareName[] = "\pAFPServer";
static char newFileShareName[] = "\pAFPSërver";
static char matchFileShareName[] = "\pAFPS≈rver";
void HandleA4ForFutureCalls(Boolean save, Boolean restore)
{
if (save)
goto saveAsm;
if (restore)
goto restoreAsm;
end: return;
asm {
@1 dc.l 1
saveAsm :
lea @1,a1
move.l a4,(a1)
jmp @end
restoreAsm :
lea @1,a4
move.l (a4),a4
jmp @end
}
}
Boolean ComparePStrings(char *first, char *second)
{
int count;
if (first[0] != second[0]) return false;
for (count=1;count<=first[0];count++)
if (first[count] != second[count]) return false;
return true;
}
void AlterPString(char *theString)
{
int count;
for (count=1;count<=newFileShareName[0];count++)
theString[count] = newFileShareName[count];
}
void AlterPStringToWildCard(char *theString)
{
int count;
for (count=1;count<=newFileShareName[0];count++)
theString[count] = matchFileShareName[count];
}
#pragma parameter __D0 PBControlIntercept(__A0)
pascal OSErr PBControlIntercept(CntrlParam *someParamBlock)
{
register CntrlParam *theParamBlock;
register short trapNumber;
register char *typeName;
asm {
move.l a0, theParamBlock // Copy A0 into a place the compiler knows about
move.w d0, trapNumber
pea @returnAddress // Push address for return from real handler
clr.l -(sp) // Push space for the real handler address
}
PushRegs(); // Save any temp regs we might use in C code,
// and save A4.
HandleA4ForFutureCalls(false,true);
asm { move.l OriginalPBControl, 20(sp) }
if (theParamBlock) {
if (theParamBlock->ioCRefNum == -10) {
if (theParamBlock->csCode == lookupName) {
typeName = (char*)*(long *)(&(theParamBlock->csParam[1]));
if (typeName) {
typeName += typeName[0] + 1;
if (ComparePStrings(fileShareName,typeName)) {
AlterPStringToWildCard(typeName);
}
}
}
if (theParamBlock->csCode == registerName) {
typeName = (char*)*(long *)(&(theParamBlock->csParam[1]));
if (typeName) {
typeName += 9;
typeName += typeName[0] + 1;
if (ComparePStrings(fileShareName,typeName)) {
AlterPString(typeName);
}
}
}
}
}
PopRegs(); // Restore temp regs we might have used in C
// code, meanwhile restoring A4.
asm { rts }
returnAddress:;
asm {
movem.l (sp)+, a2/a3/d7
unlk a6
rts
}
}
pascal main()
{
RememberA0(); /* Use Think C's A4 world stuff to set up our A4. */
SetUpA4();
HandleA4ForFutureCalls(true,false); /* Save the A4 in our own code so we can use it in */
/* trap calls. */
/* Get the addresses for all relevant traps, patch them through out interceptor. */
/* Remember their addresses for chaining, too. */
OriginalPBControl = (PBRoutinePtr)(NGetTrapAddress(kPBControlTrap, 0));
NSetTrapAddress((long)&PBControlIntercept, kPBControlTrap, 0);
RestoreA4();
}